package practice.compsite;

import java.util.ArrayList;
import java.util.Iterator;

import junit.framework.TestCase;

interface Component {
	void opration();
}

class Leaf implements Component {

	private final String name;
	
	public Leaf(String name) {
		this.name = name;
	}
	
	public void opration() {
		System.out.println(name);
	}
	
}

class Note extends ArrayList<Component> implements Component {

	private static final long serialVersionUID = -5619838327365147867L;
	
	private final String name;
	
	public Note(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		return name;
	}
	
	public void opration() {
		System.out.println(name);
		for (Iterator<Component> it = iterator(); it.hasNext();) {
			it.next().opration();
		}
	}
	
}

public class CompositeStructure extends TestCase {

	public void test() {
		Note root = new Note("root");
		Note n1 = new Note("note1");
		root.add(n1);
		root.add(new Leaf("wenjian.txt"));
		root.opration();
	}
	
	public static void main(String[] args) {
		junit.textui.TestRunner.run(CompositeStructure.class);
	}
	
}
